<?php
$path_root = $_SERVER['DOCUMENT_ROOT'];

require_once($path_root. "/AppSaleOnline/libs/model.php");

class Contact extends Model
{
    public  $company_name;
    public  $email;
    public  $telephone;
    public  $address;
    public  $content;

    // set
    public function set_companyName($company_name)
    {
        $this->company_name = $company_name;
    }

    // get
    public function get_companyName()
    {
        return $this->company_name;
    }

    public function __construct()
    {
        parent::__construct();
    }

    public function set_address($address)
    {
        $this->address = $address;
    }
    public function get_address()
    {
        return $this->address;
    }

    // xoa mot contact voi id
    public function delete_contact_by_id($contact_id)
    {
        $sql = "Delete from contacts Where `contact_id` = $contact_id";

        $result = mysqli_query($this->_link, $sql);

        if($result != "")
            return true;
        return false;
    }

    // chen mot ban ghi vao contact
    public function insert_contact_into($company_name, $address, $email, $telephone, $content)
    {
        $sql = "INSERT into contacts(`company_name`, `address`, `email`, `telephone`,`content`) VALUES ('$company_name', '$address', '$email', '$telephone', '$content')";

        $result = mysqli_query($this->_link, $sql);

        if($result != "") return true;
        return false;
    }

    // lay danh sach cuat tat ca cac contact
    public function get_all_contact()
    {
        $sql = "Select * From contacts Order By `company_name`";
        $result = mysqli_query($this->_link, $sql);
        if($result != "")
        {
            $data = array();
            while($rows = mysqli_fetch_array($result, MYSQLI_ASSOC))
            {
                $data[] = $rows;
            }
            return $data;
        }
    }
}